home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / qtools0.2-src.lha / src / util / vis.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-15  |  3.0 KB  |  118 lines

  1. #define    LIBQTOOLS_CORE
  2. #define    LIBQBUILD_CORE
  3. #include <libqtools.h>
  4. #include <libqbuild.h>
  5.  
  6. struct memory bspStatic;
  7. struct memory *bspMem = &bspStatic;
  8.  
  9. extern int bitbytes;                        /* (num_visleafs+63)>>3 */
  10. extern int bitlongs;
  11. extern int c_chains;
  12. extern int c_leafsee, c_portalsee;
  13. extern int c_portalskip, c_leafskip;
  14. extern int c_portaltest, c_portalpass, c_portalcheck;
  15. extern int c_vistest, c_mighttest;
  16. extern int count_sep;
  17. extern int leafon;                        /* the next leaf to be given to a thread to process */
  18. extern int originalvismapsize;
  19. extern int testvislevel;
  20. extern int totalvis;
  21. extern unsigned char *uncompressed;                /* [bitbytes*num_visleafs] */
  22. extern unsigned char portalsee[MAX_MAP_PORTALS];
  23.  
  24. extern void CalcVis(__memBase);
  25. extern void CalcAmbientSounds(__memBase);
  26.  
  27. /*
  28.  * ===========
  29.  * main
  30.  * ===========
  31.  */
  32. int main(int argc, char **argv)
  33. {
  34.   char portalfile[NAMELEN_PATH];
  35.   char source[NAMELEN_PATH];
  36.   int i;
  37.   HANDLE bspFile;
  38.   int visOptions = 0;
  39.  
  40.   memset(bspMem, 0, sizeof(struct memory));
  41.  
  42.   if (!setjmp(eabort)) {
  43.     mprintf("----- Vis ---------------\n");
  44.  
  45.     for (i = 1; i < argc; i++) {
  46.       if (!strcmp(argv[i], "-fast")) {
  47.     mprintf("fastvis = true\n");
  48.     visOptions |= VIS_FAST;
  49.       }
  50.       else if (!strcmp(argv[i], "-level")) {
  51.     testvislevel = atoi(argv[i + 1]);
  52.     mprintf("testvislevel = %i\n", testvislevel);
  53.     i++;
  54.       }
  55.       else if (!strcmp(argv[i], "-v")) {
  56.     mprintf("verbose = true\n");
  57.     visOptions |= VIS_VERBOSE;
  58.       }
  59.       else if (argv[i][0] == '-')
  60.     Error("Unknown option \"%s\"", argv[i]);
  61.       else
  62.     break;
  63.     }
  64.  
  65.     if (i != argc - 1)
  66.       Error("usage: vis [-level 0-4] [-fast] [-v] bspfile");
  67.  
  68.     strcpy(source, argv[i]);
  69.     ReplaceExt(source, "bsp");
  70.     if ((bspFile = __open(source, H_READWRITE_BINARY_OLD)) > 0) {
  71.       char *prtBuf;
  72.  
  73.       bspMem = LoadBSP(bspFile, ALL_QUAKE1_LUMPS & (~LUMP_VISIBILITY), BSP_VERSION_Q1);
  74.       bspMem->visOptions = visOptions;
  75.       AllocClusters(bspMem, LUMP_VISIBILITY);
  76.  
  77.       strcpy(portalfile, argv[i]);
  78.       ReplaceExt(portalfile, "prt");
  79.  
  80.       prtBuf = (char *)GetVoid(portalfile);
  81.       LoadPortals(prtBuf);
  82.       tfree(prtBuf);
  83.  
  84.       originalvismapsize = num_visportals * ((num_visportals + 7) / 8);
  85.       bitbytes = ((num_visportals + 63) & ~63) >> 3;
  86.       bitlongs = bitbytes / sizeof(long);
  87.  
  88.       if (!(uncompressed = (char *)kmalloc(bitbytes * num_visleafs)))
  89.     Error("Vis: failed to allocate bitbytes!\n");
  90.  
  91. /*    CalcPassages (); */
  92.       CalcVis(bspMem);
  93.  
  94.       mprintf("%5i c_chains\n", c_chains);
  95.       mprintf("%5i visdatasize (compressed from %i)\n", bspMem->shared.quake1.visdatasize, originalvismapsize);
  96.  
  97.       CalcAmbientSounds(bspMem);
  98.  
  99.       WriteBSP(bspFile, bspMem, BSP_VERSION_Q1);
  100.  
  101.       for (i = 0; i < num_visleafs; i++)
  102.     if (leafs[i])
  103.       FreeLeaf(leafs[i]);
  104.       for (i = 0; i < (num_visportals * 2); i++)
  105.     if (portals[i].winding);
  106.       FreeWinding(portals[i].winding);
  107.       tfree(leafs);
  108.       tfree(portals);
  109.       kfree();
  110.  
  111.       FreeClusters(bspMem, 0);
  112.       __close(bspFile);
  113.     }
  114.   }
  115.  
  116.   return 0;
  117. }
  118.